package br.edu.ufcg.sig.server;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.postgis.Point;

import br.edu.ufcg.sig.client.services.DelictServices;
import br.edu.ufcg.sig.server.beans.Delict;
import br.edu.ufcg.sig.server.persistence.PersistenceManager;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class DelictServicesImpl extends RemoteServiceServlet implements DelictServices {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void createDelict(String delictType, String locationType,
			String date, String delictTime, String description,
			String usedArmor, int qteVictims, int qteRobbers, String location) {
		
		
		PersistenceManager pm = new PersistenceManager();
		Delict delict;		
		try {
			delict = new Delict(delictType, locationType, date,
					delictTime, description, usedArmor,qteVictims, qteRobbers, new Point(location));
			pm.saveDelict(delict);
		} catch (SQLException e){
			e.printStackTrace();
		}
		
	}

	public List<String> getAllPoints() {
		PersistenceManager pm = new PersistenceManager();
		List<Delict> delicts = pm.getAllDelicts();
		List<String> points = new ArrayList<String>();
		for (Delict delict : delicts) {
			points.add(delict.getLocation().toString());
		}
		return points;
	}

	public List<String> getHotZones() {
		PersistenceManager pm = new PersistenceManager();
		return pm.getHotZones();
		
	}
	

}
